home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / DebugTool_111.lha / srcstuffing.c < prev    next >
C/C++ Source or Header  |  1992-10-31  |  5KB  |  195 lines

  1. #include "frobnitz.h"
  2.  
  3. /*******************************************************************/
  4. /*  Funktion: seek_pos                                             */
  5. /*******************************************************************/
  6.  
  7. void
  8. seek_pos (z_word pos)
  9. {
  10.   if (fseek (DatFile, ((unsigned long) (pos + (header_level) * 512)), SEEK_SET) != 0)
  11.     quit (1);
  12. }
  13.  
  14. /*******************************************************************/
  15. /*  Funktion: newline                                              */
  16. /*******************************************************************/
  17.  
  18. void
  19. newline (void)
  20. {
  21.   printf ("\n");
  22. }
  23.  
  24. /*******************************************************************/
  25. /*  Funktion: power  --- thanx to K&R :-)                          */
  26. /*******************************************************************/
  27.  
  28. int
  29. power (int base, int n)
  30. {
  31.   int p;
  32.  
  33.   for (p = 1; n > 0; --n)
  34.     p = p * base;
  35.   return p;
  36. }
  37.  
  38. /*******************************************************************/
  39. /*  Funktion: parse                                                */
  40. /*******************************************************************/
  41.  
  42. void
  43. parse (char *parm)
  44. {
  45.   switch (*parm)
  46.     {
  47.       case '/':
  48.       parse_opt (*++parm);
  49.       break;
  50.     case '-':
  51.       while (*++parm)
  52.     parse_opt (*parm);
  53.       break;
  54.     default:
  55.       fprintf (stderr, "Unknown parameter: %s\n", parm);
  56.       break;
  57.     }
  58. }
  59.  
  60. /*******************************************************************/
  61. /*  Funktion: parse_opt                                            */
  62. /*******************************************************************/
  63.  
  64. void
  65. parse_opt (char p)
  66. {
  67.   switch (p)
  68.     {
  69.       case '0':
  70.       no_enum = 1;
  71.       break;
  72.     case '1':
  73.       no_attr = 1;
  74.       break;
  75.     case '2':
  76.       dec_enum = 1;
  77.       break;
  78.     case '3':
  79.       no_props = 1;
  80.       break;
  81.     case 'h':
  82.       header_print = 1;
  83.       break;
  84.     case 'g':
  85.       game_print = 1;
  86.       break;
  87.     case 'a':
  88.       alphabet_print = 1;
  89.       break;
  90.     case 'm':
  91.       macros_print = 1;
  92.       break;
  93.     case 'o':
  94.       object_print = 1;
  95.       break;
  96.     case 't':
  97.       tree_print = 1;
  98.       break;
  99.     case 'd':
  100.       vocab_print = 1;
  101.       break;
  102.     case 'v':
  103.       var_print = 1;
  104.       break;
  105.     case 'c':
  106.       do_check = 1;
  107.       break;
  108.     default:
  109.       fprintf (stderr, "Unknown option: %c\n", p);
  110.       break;
  111.     }
  112. }
  113.  
  114. /*******************************************************************/
  115. /*  Funktion: quit                                                 */
  116. /*******************************************************************/
  117.  
  118. void
  119. quit (int i)
  120. {
  121.   error (i);
  122.  
  123.   fclose (DatFile);
  124.   exit (0);
  125. }
  126.  
  127. /*******************************************************************/
  128. /*  Funktion: error                                                */
  129. /*******************************************************************/
  130.  
  131. void
  132. error (int i)
  133. {
  134.   static char *errtype[] =
  135.   {
  136.     "",
  137.     "File too short",
  138.     "Not an Infocom file",
  139.     "Unknown vocabulary type",
  140.     "Macro too long",
  141.     "Object too long",
  142.     "EncStr too long",
  143.     "DecStr too long",
  144.     "Can't perform that on a savefile",
  145.     "No verify info in header"
  146.   };
  147.  
  148.   fprintf (stderr, "%s%s\n", (i ? "Error: " : ""), errtype[i]);
  149. }
  150.  
  151. /*******************************************************************/
  152. /*  Funktion: helptxt                                              */
  153. /*******************************************************************/
  154.  
  155. void
  156. helptxt (void)
  157. {
  158.   printf (STAMP);
  159.   printf (" - Copyright (c) 1992 Paul David Doherty\n");
  160.   printf ("All rights reserved. Not for commercial use.\n\n");
  161.   printf ("\
  162. Usage: DebugTool [-<options>] -<modifiers> <file>\n\
  163. \n\
  164.                         Where <options> is one of:\n\
  165. \n\
  166.   -g  Display game name                -h  Display game header\n\
  167.   -a  Print alphabet                   -m  Print macros\n\
  168.   -o  Print object list                -t  Print object tree\n\
  169.   -v  Print variables                  -d  Print dictionary\n\
  170.   -c  Check file\n\
  171. \n\
  172.                         And <modifiers> is one of:\n\
  173. \n\
  174.   -0  Suppress enumeration             -1  Suppress attributes\n\
  175.   -2  Decimal enumeration              -3  Suppress properties");
  176. }
  177.  
  178. /*******************************************************************/
  179. /*  Funktion: byteswap  --- thanks to MA Howell                    */
  180. /*******************************************************************/
  181.  
  182. z_word
  183. byteswap (z_word word)
  184. {
  185. /* for big-endian machines */
  186. #ifdef AMIGA
  187.   return (word);
  188.  
  189. /* for little-endian machines */
  190. #else
  191.   return (((word << 8) & 0xff00) | ((word >> 8) & 0xff));
  192.  
  193. #endif
  194. }
  195.